package com.sds.sweng.swat.miplatform.ui.design.models.commands;

import org.eclipse.gef.commands.Command;

import com.sds.sweng.swat.miplatform.ui.design.models.MiplatformComponent;
import com.sds.sweng.swat.miplatform.ui.design.models.MiplatformContainer;

public class CreateCommand extends Command {

	private MiplatformContainer parent;
	private MiplatformComponent child;
	private int index;

	public CreateCommand(MiplatformContainer parent, MiplatformComponent child) {
		this(parent, child, -1);
	}

	public CreateCommand(MiplatformContainer parent, MiplatformComponent child, int index) {
		this.parent = parent;
		this.child = child;
		this.index = index;
	}

	public void execute() {
		if (index > 0)
			parent.addChild(child, index);
		else
			parent.addChild(child);
	}

	public void undo() {
		parent.removeChild(child);
	}
}
